package Throwable;

/*
* 自定义异常类-运行时的异常类
* */
public class MyException extends RuntimeException {

    static final long serialVersionUID = -888717899101111L;
    /*
    * 如何自定义异常类
    * 1、继承现有的异常结构，比如RuntimeException、Exception等
    * 2、提供全局变量：serialVersionUID
    * 3、提供重载的构造器
    * */
    public MyException(){

    }
    public MyException(String msg){
        super(msg);
    }

}
class TestMyException{
    /*
     * 手动抛出异常
     * */
    public static void testThrow(int j){
        int i = 10;

        if (j>0){
            System.out.println(i/j);
        }else {
            throw new MyException("分母不能为零！");
        }
    }

    public static void main(String[] args) {
        throw_.testThrow(0);
    }
}
